<?php
// +----------------------------------------------------------------------+
// | Yahe Famliy [ THE BEST WISH FOR YOU ]
// +----------------------------------------------------------------------+
// | Copyright (c) 2015-2080 http://www.he29.com All rights reserved.
// +----------------------------------------------------------------------+
// | Author: 莎拉酱° <iyahe@qq.com> <Delicious not Shala sauce you were worth it >
// +----------------------------------------------------------------------+
class TagAction extends Action{
   public function _initialize(){
		//parent::_initialize(); //先调用父级
	}
	/**
	 * [index tag标签首页控制器]
	 * @return [type] [description]
	 */
    public function index(){
    	$data = M('tag')->order('id desc')->select();
    	$this->assign('data',$data);
    	$this->display();
    }
	/**
	 * [add xinzeng]
	 */
    public function add(){
    	if (IS_POST) {
    		//暂时不做数据库入库前的处理了啊~所以`
    		$data = array('tagname'=>$_POST['tagname'],'order'=>$_POST['order'],'addtime'=>time());
    		if ($_GET['id']) {
    			$result = M('tag')->where(array('id'=>intval($_GET['id'])))->save($data);
    		}else{
    			$result = M('tag')->add($data);
    		}
    		
    		if ($result) {
    			$this->success('更新成功');
    		}else{
    			$this->error('更新失败');
    		}
    	}else{
    		$id = intval($_GET['id']);
    		$tag = M('tag')->where(array('id'=>$id))->find();
    		$this->assign('tag',$tag);
    		$this->display();
    	}
    	
    }

    public function delete(){
    	$id = intval($_GET['id']);
    	$result = M('tag')->where(array('id'=>$id))->delete();
    	if ($result) {
    			$this->success('删除成功');
    		}else{
    			$this->error('删除失败');
    		}
    }
}